package team.cdlzz.config.websocket;

/**
 * @author zw
 * @date 2022-06-20.
 */


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.HandshakeInterceptor;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
import team.cdlzz.controller.UpWebSocketController;
import team.cdlzz.controller.WebSocketController;
import team.cdlzz.dao.UserMapper;
//
//@Configuration
//@EnableWebSocket
//public class WebSocketConfig implements WebSocketConfigurer {
//    //注入到容器中,会自动去注册 websocket  服务
//    @Bean
//    public ServerEndpointExporter serverEndpointExporter() {
//        return new ServerEndpointExporter();
//    }
//
//    @Autowired
//    WebSocketInterceptor webSocketInterceptor;
//
//    @Autowired
//    WebSocketHandling webSocketHandling;
//
//    @Override
//    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
//        registry.addHandler(this.webSocketHandling, "/socket/{name}","/**")
//                .setAllowedOrigins("*")
//                .addInterceptors(this.webSocketInterceptor);
//    }
//}

@Configuration
//@EnableWebSocket
public class WebSocketConfig{

    //注入到容器中,会自动去注册 websocket  服务
    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    @Autowired
    UserMapper userMapper;
    @Autowired
    public void setSenderService(){
        WebSocketController.userMapper = userMapper;
    }

    @Autowired
    public void setSenderServiceUP(){
        UpWebSocketController.userMapper = userMapper;
    }

//    @Autowired
//    WebSocketInterceptor webSocketInterceptor;
//
//    @Autowired
//    WebSocketHandling webSocketHandling;

//    @Override
//    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
//        registry.addHandler(this.webSocketHandling, "/socket/{name}","/**")
//                .setAllowedOrigins("*")
//                .addInterceptors(this.webSocketInterceptor);
//    }


}